/**
 * \file PageMap.h
 * \brief Page bitmap allocator
 * \author Corey Tabaka
 */

/*
   Copyright 2006 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include <ktypes.h>

#ifndef __KERNEL_PAGE_MAP_H__
#define __KERNEL_PAGE_MAP_H__

class PageMap {
	private:
	
	uint32 super[32];
	uint32 page[32*32][32];
	
	uint32 base;
	uint32 limit;
	
	uint32 totalAlloc;
	uint32 totalFree;
	uint32 currentAlloc;
	uint32 currentFree;
	
	public:
	
	PageMap(void);
	PageMap(uint32 base, uint32 limit);
	~PageMap(void);
	
	void initialize(uint32 base, uint32 limit);
	
	bool isFree(uint32 p);
	
	bool alloc(uint32 *there, uint32 len);
	bool alloc(uint32 *there);
	
	void free(uint32 where, uint32 len);
	void free(uint32 where);
	
	void reserve(uint32 where, uint32 len);
	void reserve(uint32 where);
	
	uint32 getAllocatedPages(void);
	uint32 getPeakPages(void);
	uint32 getFreedPages(void);
	uint32 getFreePages(void);
	
	void dump(void);
	
	private:
	
	inline void updateMap(uint32 where);
};

#endif
